home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / programming / source / gblanker3.5.src.lha / GSource / Blankers / Species / blank.c next >
Encoding:
C/C++ Source or Header  |  1994-10-08  |  3.6 KB  |  161 lines

  1. /*
  2.  *  Copyright (c) 1994 Michael D. Bayne.
  3.  *  All rights reserved.
  4.  *
  5.  *  Please see the documentation accompanying the distribution for distribution
  6.  *  and disclaimer information.
  7.  */
  8.  
  9. #include <exec/memory.h>
  10. #include <dos/dos.h>
  11. #include <intuition/intuition.h>
  12. #include <clib/exec_protos.h>
  13. #include <clib/intuition_protos.h>
  14. #include <clib/graphics_protos.h>
  15. #include <clib/alib_protos.h>
  16.  
  17. #include "/Garshnelib/Garshnelib_protos.h"
  18. #include "/Garshnelib/Garshnelib_pragmas.h"
  19.  
  20. #include "Species.h"
  21. #include "//defs.h"
  22. #include "/main.h"
  23.  
  24. struct ModulePrefs
  25. {
  26.     LONG Mode;
  27.     LONG Size;
  28. };
  29.  
  30. extern __far WORD RangeSeed;
  31. extern struct ModulePrefs nP;
  32.  
  33. UWORD Table4[] = {
  34.     0x0000, 0x0B06, 0x0909, 0x060B,
  35.     0x030E, 0x003E, 0x006B, 0x0099,
  36.     0x00B6, 0x00E3, 0x03E0, 0x06B0,
  37.     0x0990, 0x0B60, 0x0E30, 0x0E03
  38.     };
  39.  
  40. #ifndef min
  41. #define min( x, y ) ( x < y ? x : y )
  42. #endif
  43.  
  44. LONG Blank( VOID *Prefs )
  45. {
  46.     LONG i, j, hei, wid, size, stable, side, offx, offy;
  47.     LONG *Phase[2] = { 0L, 0L }, Cur = 0, Pos, Species, Parent;
  48.     LONG Width, Height, RetVal = OK;
  49.     struct ModulePrefs *mP;
  50.     struct Screen *Scr;
  51.     struct Window *Wnd;
  52.     
  53.     if( SpeciesWnd )
  54.         mP = &nP;
  55.     else
  56.         mP = ( struct ModulePrefs * )Prefs;
  57.  
  58.     CurrentTime(( ULONG * )&offx, ( ULONG * )&offy );
  59.     RangeSeed = ( WORD )( offx + offy );
  60.  
  61.     Scr = OpenScreenTags( 0L, SA_DisplayID, mP->Mode, SA_Quiet, TRUE,
  62.                          SA_Overscan, OSCAN_STANDARD, SA_Depth, 4, TAG_DONE );
  63.     if( !Scr )
  64.     {
  65.         RetVal = FAILED;
  66.         goto FAIL;
  67.     }
  68.     
  69.     LoadRGB4( &Scr->ViewPort, Table4, 16 );
  70.     Width = Scr->Width;
  71.     Height = Scr->Height;
  72.     hei = Height / mP->Size;
  73.     wid = Width / mP->Size;
  74.     size = wid * hei;
  75.     side = Height / hei;
  76.     offx = ( Width - side * wid ) / 2;
  77.     offy = ( Height - side * hei ) / 2;
  78.     
  79.     Phase[0] = AllocVec( sizeof( LONG ) * size, MEMF_ANY );
  80.     Phase[1] = AllocVec( sizeof( LONG ) * size, MEMF_ANY );
  81.     
  82.     if( !Phase[0] || !Phase[1] )
  83.     {
  84.         RetVal = FAILED;
  85.         goto FAIL;
  86.     }
  87.  
  88.     Wnd = BlankMousePointer( Scr );
  89.     ScreenToFront( Scr );
  90.         
  91.     while( RetVal == OK )
  92.     {
  93.         for( j = 0; ( j < hei )&&( RetVal == OK ); j++ )
  94.         {
  95.             for( i = 0; i < wid; i++ )
  96.             {
  97.                 Pos = j * hei + i;
  98.                 Phase[1-Cur][Pos] = Phase[Cur][Pos] = RangeRand( 15 ) + 1;
  99.                 SetAPen( &Scr->RastPort, Phase[Cur][Pos] );
  100.                 RectFill( &Scr->RastPort, offx + side * i, offy + side * j,
  101.                          offx + side * i + side - 2,
  102.                          offy + side * j + side - 2 );
  103.                 if(!( Pos % 200 ))
  104.                     if(( RetVal = ContinueBlanking()) != OK )
  105.                         break;
  106.             }
  107.         }    
  108.  
  109.         do
  110.         {
  111.             stable = TRUE;
  112.             CopyMemQuick( Phase[Cur], Phase[1-Cur], size * sizeof( LONG ));
  113.             for( j = 0; ( j < hei )&&( RetVal == OK ); j++ )
  114.             {
  115.                 for( i = 0; i < wid; i++ )
  116.                 {
  117.                     Pos = j * hei + i;
  118.                     Species = Phase[Cur][Pos];
  119.                     if( Species == 15 )
  120.                         Parent = 1;
  121.                     else
  122.                         Parent = Species + 1;
  123.                     if(( Phase[Cur][j*hei+((i+wid-1)%wid)] == Parent )||
  124.                        ( Phase[Cur][j*hei+((i+1)%wid)] == Parent )||
  125.                        ( Phase[Cur][((j+hei-1)%hei)*hei+i] == Parent )||
  126.                        ( Phase[Cur][((j+1)%hei)*hei+i] == Parent ))
  127.                     {
  128.                         SetAPen( &Scr->RastPort, Phase[1-Cur][Pos] = Parent );
  129.                         RectFill( &Scr->RastPort, offx + side * i,
  130.                                  offy + side * j, offx + side * i + side - 2,
  131.                                  offy + side * j + side - 2 );
  132.                         stable = FALSE;
  133.                     }
  134.                     if(!( Pos % 200 ))
  135.                         if(( RetVal = ContinueBlanking()) != OK )
  136.                             break;
  137.                 }
  138.             }
  139.             Cur = 1 - Cur;
  140.         }
  141.         while( !stable &&( RetVal == OK ));
  142.  
  143.         for( i = 0; i < 50 && RetVal == OK; i++ )
  144.         {
  145.             Delay( 2 );
  146.             RetVal = ContinueBlanking();
  147.         }
  148.     }
  149.     UnblankMousePointer( Wnd );
  150.     
  151.  FAIL:
  152.     if( Phase[0] )
  153.         FreeVec( Phase[0] );
  154.     if( Phase[1] )
  155.         FreeVec( Phase[1] );    
  156.     if( Scr )
  157.         CloseScreen( Scr );
  158.  
  159.     return RetVal;
  160. }
  161.